package com.hzit.sb2.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {
    //邮件队列
    private String FANOUT_EMAIL_QUEUE = "fanout_email_queue";
    //短信队列
    private String FANOUT_SMS_QUEUE = "fanout_sms_queue";
    //短信队列
    private String EXCHANGE_NAME = "fanoutExchange";
    //定义队列邮件
    @Bean
    public Queue fanOutEmailQueue() {
        return new Queue(FANOUT_EMAIL_QUEUE);
    }
    //定义短信队列
    @Bean
    public Queue fanOutSmsQueue(){ return new Queue(FANOUT_SMS_QUEUE); }
    // 2.定义交换机
    @Bean
    FanoutExchange fanoutExchange(){ return new FanoutExchange(EXCHANGE_NAME); }
    // 3.队列与交换机绑定邮件队列
    @Bean
    Binding bindingExchangeEmail(Queue fanOutEmailQueue, FanoutExchange fanoutExchange){
        return BindingBuilder.bind(fanOutEmailQueue).to(fanoutExchange);
    }
    // 4.队列与交换机绑定短信队列
    @Bean
    Binding bindingExchangeSms(Queue fanOutSmsQueue,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(fanOutSmsQueue).to(fanoutExchange);
    }

}

